## -*- mode: octave; -*-

PRJ = "oakbay" ;                            # model region

PRSV = false ;

### PREDICTOR SETTINGS  \\\
PAR.lon = [-133 -119] ; PAR.lat = [44 54] ; # predictor rectangle
PAR.ana = "ana" ;                           # reanalysis data
PAR.cper = [1981 1 1; 2010 12 31] ;         # full calibration period
PAR.xdscal = [1981 1 1; 1995 12 31] ;       # XDS calibration period
PAR.xdsval = [1996 1 1; 2010 12 31] ;       # XDS validation period (for selecting EOF truncation)

### input directories and netcdf predictor variables
##         "simulation"    "reference"
PAR.sim = {"gcm/fut/1"     "gcm/cur/1"} ;
##   analyses                 GCM
AVAR{1} = "air_850"  ;  SVAR{1} = "ta_850"  ; # temperature at 850 hPa
AVAR{2} = "shum_850" ;  SVAR{2} = "hus_850" ; # specific humidity at 850 hPa
AVAR{3} = "uwnd_850" ;  SVAR{3} = "ua_850"  ; # zonal wind at 850 hPa
AVAR{4} = "vwnd_850" ;  SVAR{4} = "va_850"  ; # meridional wind at 700 hPa  
AVAR{5} = "prate"    ;  SVAR{5} = "pr"      ; # precipitation
AVAR{6} = "cprat"    ;  SVAR{6} = "prc"     ; # conv. precipitation

PAR.nlon = repmat({144}, 1, length(AVAR)) ;       # longitude dimension (common for ana & gcm!)
PAR.nlat = repmat({72}, 1, length(AVAR)) ;        # latitude dimension (common for ana & gcm!)
PAR.gausslat = repmat({!true}, 1, length(AVAR)) ; # latitudes are not Gaussian (except precip)
PAR.nlon(end-1:end) = {192} ; PAR.nlat(end-1:end) = {94} ; PAR.gausslat(end-1:end) = {true} ;
### PREDICTOR SETTINGS  ///

## some defaults, modify these for custom settings
if !exist("MODSFX", "var"), MODSFX = "" ; endif #  model variants

defPAR("ptr", "ptr") ; # predictor tree
defPAR("ssn", {[10:12 1:3] [4:9]}) ;    # seasons
defPAR("res", "") ;    # resolution variants
defPAR("pdd", "pdd") ; # names of predictor and predictand files
defPAR("mod", "xds") ; # downscaling model, XDS ("xds") or multiple linear regression ("rgr")
defPAR("pcr", !true) ; # transform predictors to principal components
defPAR("qgrd", 0.3) ; # extension rate for area selection
defPAR("ptradj", "") ; # specify covariance adjustment for predictors
defPAR("ncpu", 8) ; # maximum number of cpus to use
defPAR("ptrsel", "single") ; # select predictor EOFs along single variables
defPAR("cdffit", "wbl") ; # fit function for precipitation probit
defPAR("anc", true) ; # fit annual cycle (and remove)
defPAR("trunc", "levfit") ; # PCA truncation method for predictor fields
defPAR("prbraw", !true) ; # do not use raw cdf (fit function instead)
defPAR("numhar", 5) ; # number of harmonic coefficients for annual cycle
defPAR("Pzero", 0.01) ; # threshold for zero precipitation (as fraction of mean)
defPAR("precision", "%7.1f") ; # output format
defPAR("pfy", [3 0.2 1000000 20]) ; # parameters for precipitation normalization
defPAR("neof", 200) ; # maximum number of retained EOFs
defPAR("kstest", true) ; # use Kolmogorov-Smirnov statistic for downscaled Gaussian variables
defPAR("prbwgt", [0.5 0.5]) ; # weights for cdf and inv in probit fit
defPAR("pddadj", "nopreserve") ; # adjust local Gaussian variables, with mean and variance preserved ("" equals no adjustment)
defPAR("adjfun", @prbfit) ; # local adjustment function [@prbfit @linear]
defPAR("par_opt", {"UniformOutput", false, "VerboseLevel", 0}) ; # standard options for parallel processing
defPAR("dbg", !true) ; # do not use verbose output
defPAR("Ccases", 3 * 365) ; # minimum number of cases for covariance estimation
defPAR("valscore", 2) ; # score for NEOF validation; 1: EV, 2: corr, 3: mean bias, 4: std bias
defPAR("qint", 0.9) ; # tolerance in ratio between target vs. model grid size
defPAR("udf", false) ; # discard variables that are fully undefined
defPAR("ptrout", false) ; # output ptr
defPAR("opendap", !false) ; # true if you have OPeNDAP; then move ptr_dap.lst -> ptr.lst
defPAR("ppo", 4) ; # order of pp polynomial (linear = 2 etc.)
defPAR("ptridx", []) ; # if nonempty, array of predictor variables to select
defPAR("optptr", "auto") ; # optimal ptr estimation
                              # "auto": regularized regression
                              # "manual": select number of retained EOFs from RE, KS figure
                              # "stw": stepwise XDS simulation, requires matlab statistics toolbox in ~/matlab (somewhat
			      # incompletely supported)
defPAR("reg", @lars) ;	          # Lasso/Lars as regularization method
defPAR("kfold", 3) ;	          # NEOF est. folding number
defPAR("penter", 0.05) ;	  # max. p value for entering active ptr set (optptr = "stw")
defPAR("premove", 0.1) ;	  # min. p value for exiting active ptr set (optptr = "stw")
defPAR("scyc.fun", @(p,t) p(1,:).*(1 + cos(t/2-p(2,:)).^2).^(2*p(3,:))) ; # (Taiga workaround) scale seasonal anomalies, [] if not used
defPAR("scyc.init", [1 0 1]') ;   # initialization for scyc.fun
defPAR("credsdir", [getenv("HOME") "/.esg"]) ;    # credentials directory, for netcdf download
defPAR("anaadj", false) ;			  # adjust ANA, e.g. for short calibration periods
defPAR("validx", []) ;				  # reduce validation to index validx
